<template>
  <el-container>
    <Header/>
    <el-main>

      <el-row :gutter="0" style="height: 600px">
        <el-col :span="6">
          <el-card class="box-card box-card1">
            <el-menu
              default-active="2"
              class="el-menu-vertical-demo"
              background-color="#0000"
              style="width: 270px"
              mode="horizontal"
            >
              <a href="http://www.hyit.edu.cn/" style="text-decoration: none">
              <el-menu-item index="1" style="width: 85% ;">
                  <i class="el-icon-menu"></i>
                  <span slot="title"><a style="text-decoration: none">淮工官网</a></span>
              </el-menu-item>
              </a>
              <a href="http://jwch.hyit.edu.cn/" style="text-decoration: none">
                <el-menu-item index="1" style="width: 85% ">
                  <i class="el-icon-menu"></i>
                  <span slot="title"><a style="text-decoration: none">淮工教务处</a></span>
                </el-menu-item>
              </a>
              <el-menu-item index="3" style="width: 85% ">
                <i class="el-icon-setting"></i>
                <span slot="title">导航三</span>
              </el-menu-item>
              <el-menu-item index="4" style="width: 85% ">
                <i class="el-icon-setting"></i>
                <span slot="title">导航四</span>
              </el-menu-item>
              <el-menu-item index="5" style="width: 85% ">
                <i class="el-icon-setting"></i>
                <span slot="title">导航五</span>
              </el-menu-item>
              <el-menu-item index="6" style="width: 85% ">
                <i class="el-icon-setting"></i>
                <span slot="title">导航六</span>
              </el-menu-item>
              <el-menu-item index="7" style="width: 85% ">
                <i class="el-icon-setting"></i>
                <span slot="title">导航七</span>
              </el-menu-item>
            </el-menu>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="box-card">
            <el-empty></el-empty>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="box-card box-card2" shadow="hover">
            <div v-for="o in 6" :key="o" class="text item">
              <a>{{ '列表内容 ' + o }}</a>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row style="height: 75px"></el-row>
      <el-row :gutter="0" style="height: 500px">
        <el-col :span="18">
          <el-card class="box-card1" style="height: 500px">
            <div slot="header" class="clearfix" style="height: 30px">
              <span><a style="font-size: larger;align-content: center">热帖推荐</a></span>
            </div>
            <el-carousel :interval="4000" type="card" height="330px">
              <el-carousel-item v-for="item in 6" :key="item">
                <h3 class="larger">{{ item }}</h3>
              </el-carousel-item>
            </el-carousel>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="box-card2" style="margin-left: 20px;height: 500px">
            <el-empty></el-empty>
          </el-card>
        </el-col>
      </el-row>
      <el-divider></el-divider>
      <el-card class="post-card" shadow="hover" style="margin-right: 5%" v-for="record in this.postRecords" :key="record.pid">
          <div class="post-title">
          <img src="../../assets/logo.png" class="user-avator"/>
          <div class="user-info-cont">
            <p class="username" align="left">{{ record.authorName }}</p>
          </div>
          <div class="user-info-cont">
            <p class="title-text" align="right">{{ record.title }}</p>
          </div>
        </div>
        <a @click="goToPostBody(record.pid)">
          <div class="post-content">
            <p align="left">{{ record.content }}</p>
          </div>
        </a>
        <div class="post-footer">
          <el-row :gutter="0">
            <el-col :span="1">
              <el-link type="primary" class="praise-font">点赞</el-link>
            </el-col>
            <el-col :span="1">
              <el-link type="warning" class="praise-font">点踩</el-link>
            </el-col>
            <el-col :span="1">
              <el-link type="danger" class="praise-font" @click="toInform(record)">举报</el-link>
            </el-col>
          </el-row>
        </div>
      </el-card>
      <el-pagination
        background
        layout="prev, pager, next"
        :total="this.queryParams.total"
        :page-size="this.queryParams.pageSize"
        :current-page="this.queryParams.pageNum"
        @current-change="postPage"
        style="margin-top: 50px;line-height: normal;text-align: center"
      >
      </el-pagination>
    </el-main>
    <el-footer></el-footer>
    <el-dialog title="是否需要举报" :visible.sync="informVisible" width="500px" center>
      <el-form ref="informForm" :model="informForm">
        <el-input type="hidden" name="uid" v-model="informForm.uid"/>
        <el-input type="hidden" name="pcId" v-model="informForm.pcId"/>
        <el-form-item label="活动区域: ">
        <el-select v-model="informForm.category" style="width: 300px" placeholder="请选择" :rules="[{ required: true, message: '请选择', trigger: ['blur', 'change'] }]">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="informVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitInform();informVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
import Header from '../../components/header'
export default {
  mounted () {
    console.log('this.$store.getters.getUser:' + this.$store.getters.getUser)
    this.postPage(this.currentPage)
  },
  name: 'dashboard',
  components: {
    Header
  },
  data () {
    return {
      activeIndex: '1',
      activeIndex2: '1',
      postRecords: [],
      queryParams: {
        pageNum: 1,
        pageSize: 7,
        postCode: undefined,
        postName: undefined,
        status: undefined,
        total: 1,
        currentPage: 1
      },
      currentPage: 1,
      options: [ {
        value: '1',
        label: '暴力'
      }, {
        value: '2',
        label: '色情'
      }],
      visible1: false,
      visible: false,
      visible2: false,
      informVisible: false,
      value: '',
      informForm: {
        uid: '',
        pcId: '',
        category: ''
      }
    }
  },
  methods: {
    handleSelect (key, keyPath) {
      console.log(key, keyPath)
    },
    postPage (val) {
      this.queryParams.pageNum = val
      this.$axios.get('/post/queryAll?currentPage=' + this.queryParams.pageNum).then(res => {
        this.postRecords = res.data.data.records
        this.queryParams.total = res.data.data.total
      })
    },
    goToPostBody (pid) {
      console.log(pid)
      this.$router.push({
        name: 'postBody',
        query: {
          pid: pid
        }
      })
    },
    toInform (record) {
      if (this.$store.getters.getUser === null) {
        this.$message({
          message: '请先登录',
          type: 'error'
        })
      } else {
        this.informVisible = true
        this.informForm.pcId = record.pid
        this.informForm.uid = record.authorId
      }
    },
    submitInform () {
      console.log(this.informForm)
      if (this.informForm.category !== '' && this.informForm.category !== undefined) {
        this.$axios.post('/doInform', this.informForm).then(res => {
          this.$message({
            message: '举报成功',
            type: 'success'
          })
        })
      } else {
        this.$message({
          message: '请选择一个类型',
          type: 'error'
        })
      }
    }
  }
}
</script>

<style scoped>
.el-header, .el-footer, .el-menu {
  background-color: #dde9f6;
  color: #333;
  text-align: center;
  line-height: 10%;
  font-size: larger;
}

.el-menu-item, .el-tem, .el-col, .el-col {
  height: 70px;
  text-align: center;
  line-height: 70px;
}

.el-aside {
  background-color: #e9faff;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #f4f9ff;
  color: #333;

  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

html, body, #app, .el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}

.text {
  font-size: 20px;
}

.item {
  padding: 8px 0;
  height: 50px;
  font-size: larger;
}

.box-card {
  height: 600px;
  margin-left: 20px;
  margin-top: 50px;
}
.username {
  font-size: x-large;
  font-family: "Apple SD Gothic Neo",serif;
  margin-left: 0px;
  width: 100px;
}

.box-card1 {
  margin-left: 80px;
}

.box-card2 {
  margin-right: 20%;
}
.user-avator {
  height: 50px;
}
.el-menu-item {
  font-size: larger;

}
.post-card {
  margin-left: 80px;
  height: 240px;
  margin-top: 10px;
}
.post-title {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
  height: 30px;
}
.post-content {
  line-height:1.7;
  background-color:#dde9f6;
  height: 95px;
  white-space: pre-line;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.post-footer {
  line-height:2;
  color: #999;
}
.title-text {
  align-items: last;
  padding-bottom: 20px;
  margin-bottom: 20px;
  font-size: xx-large;
}
.el-post-title {
  font-size: larger;
  font-family: "Apple Color Emoji",serif;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
  margin-top: 0;
}

.praise-font {
  font-size: large;
}
</style>
